<template>
  <div class="navbox">
    <div class="logobox flex" ref="logobox">
      <logo></logo>
    </div>

    <ul id="nav" ref="nav">
      <li @click="Link(home)" v-bind:class="{ liactive: isactive(home) }">
        <img src="@/assets/img/title/home.svg" v-if="isactive(home)" />
        <img src="@/assets/img/title/home-noactive.svg" v-else />
        首页
      </li>
      <li @click="Link(flie)" v-bind:class="{ liactive: isactive(flie) }">
        <img src="@/assets/img/title/flie.svg" v-if="isactive(flie)" />
        <img src="@/assets/img/title/flie-noactive.svg" v-else />
        文档
      </li>
      <li @click="Link(project)" v-bind:class="{ liactive: isactive(project) }">
        <img src="@/assets/img/title/project.svg" v-if="isactive(project)" />
        <img src="@/assets/img/title/project-noactive.svg" v-else />
        项目
      </li>
      <li
        @click="Link(gundamwall)"
        v-bind:class="{ liactive: isactive(gundamwall) }"
      >
        <img src="@/assets/img/title/gundam.svg" v-if="isactive(gundamwall)" />
        <img src="@/assets/img/title/gundam-noactive.svg" v-else />
        高达墙
      </li>
      <li
        @click="Link(messageboard)"
        v-bind:class="{ liactive: isactive(messageboard) }"
      >
        <img src="@/assets/img/title/board.svg" v-if="isactive(messageboard)" />
        <img src="@/assets/img/title/board-noactive.svg" v-else />
        留言板
      </li>
      <li @click="Link(aboutme)" v-bind:class="{ liactive: isactive(aboutme) }">
        <img src="@/assets/img/title/aboutme.svg" v-if="isactive(aboutme)" />
        <img src="@/assets/img/title/aboutme-noactive.svg" v-else />
        关于
      </li>
    </ul>

    <div class="basbox flex" v-show="!isshow">
      <div class="searchbox"><search></search></div>
      <div class="loginbox">
        <div class="flex flex-start" style="margin-left: 20px">
          <img
            class="active"
            src="@/assets/img/title/user.svg"
            title="登录或用户信息"
          />
        </div>
      </div>
      <div class="historybox">
        <div class="flex flex-start" style="margin-left: 20px">
          <img
            class="active"
            src="@/assets/img/title/time.svg"
            @click="historydraweropen()"
            title="历史记录"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import logo from "@/components/title/logo/logo";
import Bas from "../bas/bas.vue";
import Search from "@/components/title/search/Search";
import { mapMutations } from "vuex";

export default {
  name: "Nav",
  data() {
    return {
      home: "/home",
      flie: "/flie",
      project: "/project",
      gundamwall: "/gundamwall",
      messageboard: "/messageboard",
      aboutme: "/aboutme",
    };
  },
  props: {
    isshow: {
      type: Boolean,
    },
  },
  components: {
    logo,
    Bas,
    Search
  },
  methods: {
    ...mapMutations(["updatalocation", "updatapageindex"]),
    Link(location) {
      let href = window.location.href;
      if (href.indexOf(location) == -1) {
        this.$router.replace({
          path: location,
        });
        this.updatalocation(location);
        this.updatapageindex(this.$store.state.pageinfo.location.length);
      }
    },
    historydraweropen() {
      this.$openHistory()
    }
  },
  computed: {
    isactive(location) {
      return (location) => {
        return this.$route.path.indexOf(location) != -1;
      };
    },
  },
  watch: {},
};
</script>

<style scoped>
.navbox {
  width: 100%;
  height: 50px;
  position: relative;
  display: flex;
  align-items: flex-end;
  transition: all 0.3s ease;
  font-size: 0.8rem;
  justify-content: flex-end;
}

.logobox {
  justify-content: flex-start !important;
  position: absolute;
  left: 0%;
}

.basbox {
  display: flex;

  height: 37px;
  transition: all 0.3s ease;
}
#nav {
  margin: 0px;
  padding: 0px;
  display: flex;

  margin-right: 0px !important;
}
#nav li {
  float: left;
  list-style: none;
  color: white;
  font-weight: bold;
  padding-left: 10px;
  padding-right: 10px;
  height: 30px;
  padding-bottom: 10px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
  border-bottom: 2px solid rgba(0, 0, 0, 0);
  margin-right: 10px;
  color: lightgray;
  margin-right: 15px;
  flex-direction: row;
}
#nav li:last-child {
}
#nav li img {
  width: 20px;
  margin-right: 5px;
  transition: all 0.3s;
}
#nav li:hover {
  border-bottom: 2px solid rgba(255, 255, 255, 1);
}
#nav li:active {
  background-image: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.7),
    rgba(255, 255, 255, 0.5)
  );
}
#nav .liactive {
  color: white;
  border-bottom: 2px solid rgba(255, 255, 255, 1);
}
.basbox .active {
  cursor: pointer;
  transition: all 0.3s;
  width: 25px;
}

.basbox .active:hover {
  opacity: 0.7;
}
</style>
